<template>
	<view class="setting-page">
		<uni-list>
			<uni-list-item title="隐私协议" clickable @click="() => jump('/pagesC/policyPrivacy/index')">
			  
			</uni-list-item>
			<uni-list-item title="用户协议" clickable @click="() => jump('/pagesC/userAgreement/index')">
			  
			</uni-list-item>
			<uni-list-item title="账号注销"  clickable @click="logoff">
			  
			</uni-list-item>
		</uni-list>
		<view class="logout">
			<button class="logout-btn"  @click="logout">退出</button>
		</view>
	</view>
</template>

<script setup lang="ts">
	import { local } from "@/utils/index"
	import { clearAll } from '@/stores/clearAll.js'
	// import websocket from '@/utils/ws.js';
	import { mineServer } from '@/common/index';
	const jump = (path: string) => {
		uni.navigateTo({
			url:path
		})
	}

	const logoff = () => {
		uni.showModal({
			title:"是否注销账户",
			content:"注销后，无法登录，系统将自动删除相关个人信息（如已绑定孩子手机，请先解绑）",
			cancelText:"取消",
			confirmText:"注销",
			success: async (porps) =>{
				const {cancel, confirm} = porps;
				if(confirm){
					console.log('确认注销')
					const { status, message } = await mineServer.logout()
					if(status === '200'){
						uni.showToast({
							title:"注销成功",
							icon:"none"
						})
						setTimeout(() => {
							local.clearLocalStore();
							clearAll();
						}, 1000)
					} else{
						uni.showToast({
							title: message || "注销失败",
							icon:"none"
						})
					}
				}
			}
		})
	}
	
	const logout = () => {
		// websocket.closeWebSocket()
		local.clearLocalStore();
		clearAll();
	}
</script>

<style  lang="scss">
	// .logout{
	// 	width: 30%;
	// 	height: 80upx;
	// 	color: #fff;
	// 	position:fixed;
	// 	bottom: 100upx;
	// 	margin: 0 auto;
	// }
	
	
	.logout{
		width: calc(100% - 100upx);
		position:fixed;
		bottom: 100upx;
		left: 50upx;
		.logout-btn{
			background-color: #2BC888;
			padding:0 50upx;
			width: 100%;
			border:none;
			border-radius: 46upx;
			color: #fff;
		}
	}
</style>